/**
 * 
 */
package com.application.Adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.application.Activity.R;
import com.application.Adapter.MyConversationAdapter.ViewConversation;

public class MyConversationAdapter extends ArrayAdapter<ViewConversation> {
	private final Context _context;
	private final ArrayList<ViewConversation> _listGroup;
	int _resource;

	/**
	 * Constructor
	 * @param context
	 * @param textViewResourceId
	 * @param chat
	 */
	public MyConversationAdapter(Context context, int textViewResourceId,ArrayList<ViewConversation> listgroup){
		super(context,textViewResourceId,listgroup);
		this._context = context;
		_resource=textViewResourceId;
		_listGroup=listgroup;
	}

	/**
	 * 
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent){

		final ViewConversation viewGroup = _listGroup.get(position);

		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);;
			rowView = inflater.inflate(R.layout.listrow_infoconversation,null, true);
		}
		if(viewGroup !=null)
		{
			//holder = new ViewChatList();
			TextView txtgroupname = (TextView) rowView.findViewById(R.id.infoconversation_groupname);
			TextView txtnote = (TextView) rowView.findViewById(R.id.infoconversation_note);
			ImageView img=(ImageView)rowView.findViewById(R.id.infoconversation_imggroup);
//			txtgroupname.setText(viewGroup.get_name().toString());
			txtgroupname.setText(viewGroup._title);
			txtnote.setText(viewGroup.get_note().toString());
			if(viewGroup.get_type()==1){
			img.setImageResource(R.drawable.img_user);}
			else{
				img.setImageResource(R.drawable.img_group);
			}
			
		}
		return rowView;		
	}

	public static class ViewConversation{
		private String _name;
		private String _note;
		private int _type;//chat peer - chat group - chat invite
		private String _ip;
		private String _title; //tiêu đề để xác định chat của đối tượng nào
		private String _fullName;
		public ViewConversation(){
			_name = null;
			_note = null;
			set_type(0);
			_ip = null;
			_title = null;
			_fullName = null;
		}

		public ViewConversation(String name, String note, int type, String ip, String fullName){
			_name = name;
			_note = note;
			_type = type;
			_ip = ip;
			_fullName = fullName;
			if(_type == 1)//chat peer
				_title = _name;
			else if(_type == 2)
				_title = "Nhóm được tạo bởi " + _name;
			else if(_type == 3)
				_title = "Nhóm được yêu cầu tạo bởi: " + name;
		}
		public ViewConversation(String name, String note, String ip){
			_name = name;
			_note = note;
			//_type = type;
			_ip = ip;
			//_fullName = fullName;
			if(_type == 1)//chat peer
				_title = _name;
			else if(_type == 2)
				_title = "Nhóm được tạo bởi " + _name;
			else if(_type == 3)
				_title = "Nhóm được yêu cầu tạo bởi: " + name;
		}
		public void set_name(String _name) {
			this._name = _name;
		}

		public String get_name() {
			return _name;
		}

		void set_note(String _note) {
			this._note = _note;
		}

		String get_note() {
			return _note;
		}

		public void set_ip(String _ip) {
			this._ip = _ip;
		}

		public String get_ip() {
			return _ip;
		}

		public void set_type(int _type) {
			this._type = _type;
		}

		public int get_type() {
			return _type;
		}

		public void set_fullName(String _fullName) {
			this._fullName = _fullName;
		}

		public String get_fullName() {
			return _fullName;
		}
	}
}

















